
from feature_data.const_data import *
from feature_data.XmlData2DictData import Xml2Dict

from nd_utils.Graph_Cluster_util import *
class Graph_Paper_Cluster():

    # def __init__(self, paper_idx_set, all_paper_title_dict):
    def __init__(self, paper_idx_set, all_paper_title_dict, paper_org_dict):
        # self.nltk_util = Nltk_util()

        self.paper_idx_list = paper_idx_set
        self.paper_org_dict = paper_org_dict

        self.all_paper_title_dict = all_paper_title_dict
        self.clust_common_str_set, self.common_str_idx_dict = self._get_cluster_common_str_set_idx_dict()
        self.clust_commnon_org, self.org_idx_list = self._get_clust_commnon_org()


    def _get_cluster_common_str_set_idx_dict(self):
        clust_title_list = []
        for idx in self.paper_idx_list:
            clust_title_list.append( self.all_paper_title_dict[idx])
        return get_cluster_common_str_set_idx_dict(list(self.paper_idx_list),clust_title_list)

    def _get_clust_commnon_org(self):
        clust_org_list = []
        for idx in self.paper_idx_list:
            clust_org_list.append( self.paper_org_dict[idx] )
        return get_cluster_common_org_idx(list(self.paper_idx_list), clust_org_list)

    # def add_paper_idx_list(self, idx_list):
    #     for idx in idx_list:
    #         self.paper_idx_list.add(idx)
    #
    # def add_clust_common_str_set(self, clust_common_str_set):
    #     for str in clust_common_str_set:
    #         self.clust_common_str_set.add(str)



def get_paper_title_dict(nltk_util, publication_dict, paperid_idx_dict):
    paper_title_dict = {}
    for paperid, publication_attr_dict in publication_dict.items():
    # _title = publication_attr_dict['title']
    #     _title = nltk_util.lemma_process( publication_attr_dict['title'] )
        _title = nltk_util.stem_process( publication_attr_dict['title'] )
        paper_title_dict[ paperid_idx_dict[paperid]] = _title
    return paper_title_dict

if __name__ == '__main__':
    from nd_utils.nltk_util import Nltk_util
    nltk_util = Nltk_util()

    xml2dict = Xml2Dict(xml_filepath)
    publication_dict = xml2dict.publication_dict
    paperid_idx_dict = xml2dict.paperid_idx_dict

    paper_title_dict = get_paper_title_dict(nltk_util,publication_dict, paperid_idx_dict)

    paper_idx_set = [90, 102]
    list1 = [6, 32, 50]
    list2 = [0, 39, 47, 57]
    list3 = [10, 35, 46, 63, 75]
    list4 = [27, 37, 42, 53, 58, 65, 73, 82, 96, 98]

    # print Paper_Cluster(paper_idx_set, paper_title_dict).clust_common_str_set
    print Graph_Paper_Cluster(list1, paper_title_dict).clust_common_str_set
    print Graph_Paper_Cluster(list2, paper_title_dict).clust_common_str_set
    print Graph_Paper_Cluster(list3, paper_title_dict).clust_common_str_set
    print Graph_Paper_Cluster(list4, paper_title_dict).clust_common_str_set

    # print set([]).union(set([u'bragg grating', u'fiber bragg']))

    list5 = [0, 6, 27, 32, 37, 39, 42, 47, 50, 53, 57, 58, 65, 73, 82, 96, 98]
    print Graph_Paper_Cluster(list5, paper_title_dict).clust_common_str_set

    list6 = [52, 90, 102]

    print Graph_Paper_Cluster(list6, paper_title_dict).clust_common_str_set
    # set(['wireless sens', 'fib brag', 'network bas', 'sens network', 'brag grat'])